<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
<title>_${customer.customerName}_分拣框管理</title>
<script type="text/javascript">
  
  $(function() {
		$("#queryForm").validate(); 
  });
  
  //创建灯光架
  function createWorkBox(){
       $("#btn_submit").attr("disabled",true); 
       
	   if( $("#inputForm").valid() ){
		      var boxName=$("#boxName").val().trim();
		      var customerCode=$("#customerCode").val().trim();
		      var warehouseCode=$("#warehouseCode").val().trim();
		      
		       $.ajax({
				type : 'post',
				url : '${ctx}/workBox/ajaxCreateWorkBox',
				data : {
					boxName:boxName,
					customerCode:customerCode,
					warehouseCode:warehouseCode
				},
				dataType : 'json',
				success : function(data) {
				    if(data==true){
				       $("#queryForm").submit();
				    }else{
				       alert("网络繁忙，请稍后重试...");
				    }
				    $("#btn_submit").attr("disabled",false); 
				
				},
				error : function() {
					alert("网络繁忙，请稍后重试...");
					 $("#btn_submit").attr("disabled",false); 
				}
			});
	      
	   }else{
	       $("#btn_submit").attr("disabled",false); 
	   }
  }
  
  //重设表单
  function formReset(){
    $("input[type=reset]").trigger("click");
  }
	      
	
  //打开创建灯光架窗体
  function openWin(){
	if( $("#queryForm").valid() ){
	    formReset();
		$("#btn_submit").attr("disabled",null);
		$("#inputForm").attr("action",'${ctx}/lightShelf/createWorkBox');
		$("#warehouseCode").val($("#_warehouseCode").val());
		$("#customerCode").val($("#_customerCode").val());
		$("#newWorkBox").trigger("click");
		
	}
  }
  
  //删除
  function ajaxDelete(boxId){
     
     $.ajax({
			type : 'post',
			url : '${ctx}/workBox/ajaxDelete',
			data : {
				boxId:boxId
			},
			dataType : 'json',
			success : function(data) {
			    if(data==true){
			       $("#queryForm").submit();
			    }else{
			       alert("网络繁忙，请稍后重试...");
			    }
			
			},
			error : function() {
				alert("网络繁忙，请稍后重试...");
			}
		});
  }
  
  //free
  function ajaxFree(boxId){
     
     $.ajax({
			type : 'post',
			url : '${ctx}/workBox/ajaxFree',
			data : {
				boxId:boxId
			},
			dataType : 'json',
			success : function(data) {
			    if(data==true){
			       $("#queryForm").submit();
			    }else{
			       alert("网络繁忙，请稍后重试...");
			    }
			
			},
			error : function() {
				alert("网络繁忙，请稍后重试...");
			}
		});
  }
  
  //init打印机
  function initPrinter(item) {
		//var indexLength = getPrinterCount();
		//var tempString = "";
		//for ( var i = 0; i < indexLength; i++) {
		//	var name = getPrinterName(i);
		//	tempString += "<option value='"+name+"'>" + name + "</option>";
		//}
		$("#printerNumber").html("打印编码(<font color=blue>" + item + "</font>)");
		$("#hiddenCode").val(item);
		//$("#printerBody").html(tempString);
	  packFormPrinter("printerBody");
  }
  
  //获得打印机的个数
  function getPrinterCount() {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
		return LODOP.GET_PRINTER_COUNT();
  }
	
  //根据打印机序号获得打印机名称
  function getPrinterName(iPrinterNO) {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
		return LODOP.GET_PRINTER_NAME(iPrinterNO);
  }
  
  //打印
  function clickPrinter() {
		var code = $("#hiddenCode").val();
		var printName = $("#printerBody").val();
		printBarCode(printName, code);
  }
  
  function printBarCode(printName, taskName) {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
		LODOP.PRINT_INIT(taskName);
		LODOP.SET_PRINT_PAGESIZE(1, 500, 318, "");
		LODOP.ADD_PRINT_BARCODE(25, 10, 180, 40, "128B", taskName);
		LODOP.SET_PRINT_STYLE("FontName","SimHei");
	    LODOP.SET_PRINT_STYLE("FontSize",25);
		LODOP.ADD_PRINT_TEXT(70, 30, 200,100,taskName);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT();
		}
  }
  
  

</script>
</head>

<body>
<section class="content">
<div class="row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">			     
		     <form class="form-search" id="queryForm" method="post" action="${ctx}/workBox/v2_queryWorkBox" style="margin-top: 10px;">
			 	<div class="form-group row">
						<div class="col-sm-3">
							<div class="input-group col-sm-12">
			 	<label class="input-group-text">商家:</label>
				 <select  name="_customerCode"  id="_customerCode" value="${param._customerCode}"  class="form-control required" onchange="ajaxAreaGroup(this,'_warehouseCode');">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${param._customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
			 	</div>
			 	</div>
			 	
			 	<div class="col-sm-3">
							<div class="input-group col-sm-12">
			 	
				<label class="input-group-text">仓库:</label>
				 <select  name="_warehouseCode"  id="_warehouseCode" class="form-control required" >
				 <option value=""></option>
				 	<c:forEach items="${warehouseList}" var="warehouse">
						<option value="${warehouse.groupCode}" <c:if test="${param._warehouseCode eq warehouse.groupCode}">selected=selected</c:if>
						>${warehouse.groupName}</option>
					</c:forEach>
				</select>
				</div>
				</div>
				
				<div class="col-sm-4">
							<div class="input-group col-sm-12">
			    <button class="btn btn-info" type="submit" style="margin-left: 10px;">搜索</button>
			    <a  data-toggle="modal" role="button" style="margin-left: 10px;" class="btn btn-primary" onclick="openWin();" >添加分拣框</a>
			    <a href="#win_newWorkBox" role="button" id="newWorkBox" data-toggle="modal" style="display: none;"></a>
			    </div>
			    </div>
			    </div>
		    </form>
	</div>
	</div>
	</div>
	</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>					
			    <th style="width: 50px;">序号</th>
			    <th>商家名称</th>
			    <th>仓库名称</th>
			    <th>分拣框名称</th>
			    <th>分拣框编号</th>
			    <th>当前任务编码</th>
			    <th>状态</th>
			    <th>操作</th>
			</tr></thead>
		<tbody>
		<c:forEach items="${workBoxList}" var="box" varStatus="i">
			<tr>
			   <td>${i.count}</td>
			   <td>${box.customerCode}</td>
			   <td>${box.warehouseCode}</td>
			   <td>${box.boxName}</td>
			   <td>${box.boxCode}</td>
			   <td>${box.taskCode}</td>
			   <td >
			     <c:if test="${box.status eq 'free'}">空置中</c:if>
			     <c:if test="${box.status eq 'busy'}"><font color=red>使用中</font></c:if>
			   </td>
			   <td>
			   		<shiro:hasRole name="admin">
			       <c:if test="${box.status eq 'busy'}">
			          <button style="display: none;"  class="btn btn-danger" onclick="ajaxFree('${box.id}');">释放</button>
			       </c:if> 
			       <c:if test="${box.status eq 'free'}">
			          <button  class="btn btn-primary" onclick="ajaxDelete('${box.id}');">删除</button>
			       </c:if> 
			       </shiro:hasRole>
			       <a href="#selextPrinter" role="button" data-toggle="modal" class="btn btn-primary" onclick="initPrinter('${box.boxCode}')">打印条码</a>
								
			   </td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<!-- 分拣框 窗体 --> 
	<div class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="win_newWorkBox" >
		<div class="modal-dialog" >
		<div class="modal-content">
		
		<div class="modal-header">
			<h4>创建分拣框</h4>
		</div>
		
		<div class="modal-body">
		<form id="inputForm"  method="post" class="form-horizontal">
		   <fieldset>
				  <!-- 行1 -->
			      <div class="form-group row">
						<div class="col-sm-6">
							<div class="input-group col-sm-12">
								<label  class="input-group-text">分拣框名称:</label>
								    <input type="text" id="boxName" name="boxName" class="form-control required" >
								    <input type="hidden" id="customerCode" name="customerCode" >
								    <input type="hidden" id="warehouseCode" name="warehouseCode" >
								    <input type="hidden" id="hiddenCode" name="hiddenCode" >
								    <input id="btn_reset" type="reset" style="display:none;" /> 
			      </div>
			      </div>
			      </div>
			</fieldset>	 
			</form>
		</div>
		
		<div class="modal-footer">
		    <button id="btn_submit" class="btn btn-primary" onclick="createWorkBox();">确定创建</button>&nbsp;	 
			<button id="btn_cancel" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">返回</button>
		</div>
	</div>
	</div>
	</div>
	
	<!-- 打印条码窗体 -->
	<div style="width: 1000" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="selextPrinter">
		 <div class="modal-dialog" >
		<div class="modal-content">
		 <div class="modal-header">
			  <h3 id="printerNumber">打印条码</h3>
		  </div>
			
		  <div class="modal-body" style="margin-left: 100px;">
			  <select id="printerBody" name="printerBody" style="width: 300px;"></select>
		  </div>
			
		  <div class="modal-footer">
			  <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true" id="printer" onclick="clickPrinter()">开始打印</button>
			  <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">取消</button>
		  </div>
		</div>
		</div>
	</div>
</section>
</body>
</html>
